#ifndef _VFX_COMPONENTS_H_
#define _VFX_COMPONENTS_H_

#include "ui/ui_sprite.h"
#include "math/counter.h"
#include "math/ramp.h"
#include "num/rand.h"

#include <vector>

namespace vfx
{

class		VFXGradients
{
public:
	struct				Gradient
	{
		Gradient(float frm, float to, float time, float delay) : From(frm), To(to), Prog(time), Delay(delay) {}
		float			From, To, Delay;
		math::Counter	Prog;
	};

	VFXGradients();
	virtual ~VFXGradients();

	void					SetImage(const std::string& Name) { m_Gradient.Create(Name); };
	void					AddGradient(Gradient* pRay)
	{
		m_Gradients.push_back(pRay);
	}
	void					AddGradient(float From, float To, float Time, float Delay)
	{
		AddGradient(new Gradient(From, To, Time, Delay)); 
	}
	virtual void			Tick(float dt);
	virtual void			Render(const math::Vec2& Offset, float Scale);
	void					SetPos(const math::Vec2& P) { m_Pos = P; };
	bool					IsDone() const { return m_Gradients.empty(); };
private:
	math::Vec2				m_Pos;
	ui::UISprite			m_Gradient;
	std::vector<Gradient*>	m_Gradients;
};

class		VFXGodRays
{
public:
	struct				GodRay
	{
		math::Vec2		Center;
		float			Rot, RotSpeed, Length;
		math::Counter	Prog;
	};

	VFXGodRays();
	virtual ~VFXGodRays();

	void					SetImage(const std::string& Name) { m_GodRay.Create(Name); };
	void					AddGodRay(GodRay* pRay)
	{
		m_GodRays.push_back(pRay);
	}
	virtual void			AddGodRay(const math::Vec2& Center, float Rot, float RotSpeed, float Length, float Time)
	{
		GodRay* pRay = new GodRay;
		pRay->Center = Center;
		pRay->Length = Length;
		pRay->Prog.SetLimit(Time);
		pRay->Rot = Rot;
		pRay->RotSpeed = RotSpeed;
		AddGodRay(pRay);
	}
	virtual void			AddGodRay()
	{
		// use default parameters
		num::RAND32& rnd = num::RAND32::Instance();

		AddGodRay(math::Vec2(0,0), rnd.RandFloat(0, 360), rnd.RandFloat(-30, 30), m_Radius, rnd.RandFloat(0.4f, 0.8f));
	}

	virtual void			Tick(float dt);
	virtual void			Render(const math::Vec2& Offset, float Scale);
	void					SetPos(const math::Vec2& P) { m_Pos = P; };
	void					SetRadius(float f) { m_Radius = f; };
	bool					IsDone() const { return m_GodRays.empty(); };
protected:
	math::Vec2				m_Pos;
	float					m_Radius;
	ui::UISprite			m_GodRay;
	std::vector<GodRay*>	m_GodRays;
	math::ColorRamp			m_Colors;

};

}

#endif //_VFX_COMPONENTS_H_